package com.javaclimb.jxnu.controller;

import com.javaclimb.jxnu.dao.LabelUsersMapper;
import com.javaclimb.jxnu.domain.Label_users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

import static org.apache.commons.lang3.ObjectUtils.isEmpty;

@RestController
@RequestMapping("/LabelUsers")
public class LabelUsersController {
    @Autowired
    LabelUsersMapper labelUsersMapper;

    @RequestMapping("/addlabeluser")
    public Result addlabeluser(@RequestBody Label_users label_users) {
        Label_users x=labelUsersMapper.selectlabel(label_users.getLabel_name(),label_users.getUser_id());
        if(x==null){
        labelUsersMapper.addlabeluser(label_users);
        return new Result(Code.SUCCESS, "添加成功");}
        return new Result(Code.FAIL, "已有标签，添加失败");
    }

    @RequestMapping("/findlabel/{user_id}")
    public Result addlabeluser(@PathVariable int user_id) {
        List<Map<String,Object>> x=labelUsersMapper.findlabel(user_id);
        return new Result(Code.SUCCESS, "添加成功",x);
    }

    @RequestMapping("/deletelabel")
    public Result deletelabel(@RequestBody Label_users label_users) {
       labelUsersMapper.deletelabel(label_users);
        return new Result(Code.SUCCESS, "删除成功");
    }
}
